using System;
using System.Collections.Generic;
using AirSimUnity;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.Serialization;


/// <summary>
/// 碰撞记录器，用于记录无人机碰撞到的物体
/// </summary>
public class DroneCollierData : MonoBehaviour
{
    public List<GameObject> droneList = new List<GameObject>();
    private Color discColor = Color.green;
    public string vehicleName;
    public float radius = 1f;
    public OptimizedHexGrid grid;

    [Button]
    public void Start()
    {
        vehicleName = GetComponent<Drone>().vehicleName;
        gameObject.name = vehicleName;
    }


    public void Update()
    {
        grid.ScanAreaDecrease(transform.position, radius);
    }

    public void OnTriggerEnter(Collider other)
    {
        discColor = Color.red;
        if (other.gameObject.CompareTag("Floor"))
            return;
        droneList.Add(other.gameObject);
        Debug.Log("OnTriggerEnter" + other.gameObject.name);
    }

    public void OnTriggerExit(Collider other)
    {
        discColor = Color.green;
    }


    private void OnDrawGizmos()
    {
        UnityEditor.Handles.color = discColor;
        UnityEditor.Handles.Label(transform.position, vehicleName + ":" + transform.position);
        if (StaticState.ShowRadius)
            UnityEditor.Handles.DrawWireDisc(transform.position, Vector3.up, radius);
    }
}